﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Path.Question;

namespace Path.Answer
{
    class Effie:IPath
    {
        public string GetRelativePath(string currentPath, string targetPath)
        {
            string RelativePath = null;
            int difIndex = 0;
            List<string> pathlist=new List<string>();
            int i = 0;
            string[] current = currentPath.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
            string[] target = targetPath.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
            for (i = 0; i < Math.Min(current.Length, target.Length); i++)
            {
                if (current[i] != target[i])
                {
                    
                    break;
                }
            }
            difIndex = i;
            for (i = current.Length; i > difIndex; i--)
            {
                pathlist.Add("..");
            }
             for (i = difIndex; i < target.Length; i++)
            {
                    pathlist.Add(target[i]);
            }
             for (i = 0; i < pathlist.Count-1; i++)
             {
                 RelativePath += pathlist[i]+"/";
             }
             RelativePath += pathlist[pathlist.Count - 1];
             return RelativePath;
        }
    }
}
